//
//  Singer_categoryVC.m
//  K-Music
//
//  Created by CHUN on 16/2/18.
//  Copyright © 2016年 CHUN. All rights reserved.
//

#import "Singer_categoryVC.h"

@interface Singer_categoryVC ()<UITableViewDataSource ,UITableViewDelegate>

@property (nonatomic ,strong) UITableView * TableView;

@property (strong,nonatomic)NSMutableArray * SingerDataArray;
@property (strong,nonatomic)NSMutableArray * Singer_IdData;

@end

@implementation Singer_categoryVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGB(241, 241, 241);
    self.navigationItem.title = @"歌星点歌";
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"back" highIcon:@"back" target:self action:@selector(back_back)];
    
    [self creatUI];
}
- (void)back_back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -creatUI-
- (void)creatUI
{
    self.TableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT ) style:UITableViewStylePlain];
    self.TableView.delegate = self;
    self.TableView.dataSource =self;
    self.TableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.TableView.backgroundColor = RGB(241, 241, 241);
    [self.view addSubview:self.TableView];
    
    self.SingerDataArray = [[NSMutableArray alloc]init];
    self.Singer_IdData = [[NSMutableArray alloc]init];
    Singer_category_mode * mode = [[Singer_category_mode alloc]init];
    
    for (int i = 0; i<[User_information conversion].Singer_category_Data.count ; i++) {
        
        mode = [User_information conversion].Singer_category_Data[i];
        [self.SingerDataArray addObject:mode.name];
        [self.Singer_IdData addObject:mode.aid];
        
    }
    NSLog(@"%@",self.SingerDataArray);
   
}

#pragma mark ------- UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.SingerDataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"cellID";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        
    }
    NSString *title = [self.SingerDataArray objectAtIndex:indexPath.row];
    cell.textLabel.text = title ;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType  = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSLog(@"%@",self.Singer_IdData[indexPath.row]);

    Detailed_SingerVC * singer = [[Detailed_SingerVC alloc]init];
    singer.Sing_ID = self.Singer_IdData[indexPath.row];
    [self.navigationController pushViewController:singer animated:YES];
    
    [tableView deselectRowAtIndexPath:tableView.indexPathForSelectedRow animated:YES];
    
    
}


@end
